#include <window.h>

namespace lgb_gtk
{

  int Window::AddCloseEventListener(int (*f)(void *data) , void *newData)
  {
    if( NULL == f )
      return 1;
    
    CloseFunctions[f] = newData;
    
    return 0;
  }

  int Window::CloseFunctionsBase()
  {
    map<int (*)(void *) , void*>::iterator it = CloseFunctions.begin();
    while( it != CloseFunctions.end() )
      {
	it->first(it->second);
	it++;
      }
    return 0;
  }

  int Window::RemoveCloseEventListener(int (*f)(void *data))
  {
    map<int (*)(void *) , void*>::iterator it = CloseFunctions.begin();
    while( it != CloseFunctions.end() )
      {
	if(it->first == f)
	  {
	    CloseFunctions.erase(it);
	    return 0;
	  }
      }
    return 1;
  }
  
}
